package day05;

import java.util.Arrays;

/**
 * 数组
 * 是一种引用数据类型
 * 存放相同数据元素的集合
 */
public class ArrayTestDemo {
    public static void main(String[] args) {
        ArrayTestDemo arrayTestDemo = new ArrayTestDemo();

        /**
         * 数组的声明、初始化、访问
         */
        int[] a1 = new int[3];//1、byte,short,int,char默认值0/2、long默认值0L3、float默认值0.0f，double默认值0.0
        System.out.println(Arrays.toString(a1));

        float[] a11 = new float[3];
        System.out.println(Arrays.toString(a11));

        double[] a2 = new double[3];
        System.out.println(Arrays.toString(a2));
        boolean[] a3 = new boolean[3];
        System.out.println(Arrays.toString(a3));

        int[] a4 = new int[5];
        int[] a5 = {1,2,3};
        int[] a6 = new int[]{1,2,5};
        int[] a7;
        a7 = new int[]{2,5,8};

        System.out.println(a4.length);
        System.out.println(a5.length);

        System.out.println(a5[1]);
        /**
         * 数组的迭代/遍历
         */
        int[] arrInt = new int[10];
        for(int i = 0; i<10;i++){
            arrInt[i] =(int)(Math.random()*100+1);//将数组元素赋值为1-100的整数
            System.out.println(arrInt[i]);
        }
        /**
         * 数组元素最大值
         */
        int maxValue=arrInt[0];
        for(int i= 0;i<arrInt.length;i++){
            if(maxValue<arrInt[i]){
                maxValue=arrInt[i];
            }
        }
        System.out.println(maxValue);

        /**
         * 数组复制
         */
        long[] a = {1,2,3,4,5};
        long[] b = new long[6];
        //a:源数组
        //1:源数组的起始下标
        //b:目标数组
        //0:目标数组的起始下标
        //4:要复制的元素个数
        System.arraycopy(a,1,b,0,4);
        System.out.println(Arrays.toString(b));
        //a:源数组
        //b1:目标数组
        //3:目标数组的长度
        //  --若目标数组长度>源数组长度，则末尾补默认值
        //  --若目标数组长度<源数组长度，则将末尾的截掉
        long[] b1 =Arrays.copyOf(a,3);
        System.out.println(Arrays.toString(b1));

        /**
         * 数组扩容
         */
        int[] c = new int[5];
        c = Arrays.copyOf(c,c.length+1);
        System.out.println(Arrays.toString(c));

        /**
         * 数组排序
         */
        int[] d = new int[]{76,234,24,13,494,876,685};
        Arrays.sort(d);
        System.out.println(Arrays.toString(d));



    }


}
